package com.ruoyi.session.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.session.domain.Session;
import com.ruoyi.session.domain.SessionDto;
import com.ruoyi.session.service.ISessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: RuoYi-Vue-master
 * @description:
 * @author: xgw
 * @create: 2025-01-07 17:21
 **/


@RestController
@RequestMapping("/system/session")
public class SessionController  extends BaseController {

    @Autowired
    private ISessionService iSessionService;

    /**
    * @Description: 查询出所有的会话
    * @Param: []
    * @return: com.ruoyi.common.core.domain.AjaxResult
    * @Author: xgw
    * @Date: 2025/1/13
    */

    @GetMapping("/selectExistSession")
    public AjaxResult selectExistSession() {
        return iSessionService.selectExistSession();
    }

    /**
     * 插入会话
     * @param session
     * @return
     */
    @PostMapping("/insertSession")
    public AjaxResult insertSession(@RequestBody Session session) {
        return AjaxResult.success("插入成功！！",iSessionService.insertSession(session));
    }
    /**
    * @Description: 删除历史会话
    * @Param: [sessionId]
    * @return: com.ruoyi.common.core.domain.AjaxResult
    * @Author: xgw
    * @Date: 2025/1/13
    */

    @GetMapping("/deleteSessionBySessionId/{sessionId}")
    public AjaxResult deleteSessionBySessionId(@PathVariable("sessionId") Integer sessionId) {
        return AjaxResult.success("删除成功",iSessionService.deleteSessionBySessionId(sessionId));
    }

    /**
     * 动态查询历史会话
     * @param sessionDto
     * @return
     */
    @PostMapping("/dynamicSelectSession")
    public AjaxResult dynamicSelectSession(@RequestBody SessionDto sessionDto) {
        return iSessionService.dynamicSelectSession(sessionDto.getUsername(), sessionDto.getStrategyId(), sessionDto.getTitle());
    }

    /**
    * @Description: 查询历史会话
    * @Param: [userId]
    * @return: com.ruoyi.common.core.domain.AjaxResult
    * @Author: xgw
    * @Date: 2025/1/13
    */
    @GetMapping("/selectHistorySession/{userId}")
    public AjaxResult selectHistorySession(@PathVariable("userId") Integer userId){
        return iSessionService.selectHistorySession(userId);
    }

    /**
    * @Description: 查询出搜索的会话 模糊查询
    * @Param: [title, userId]
    * @return: com.ruoyi.common.core.domain.AjaxResult
    * @Author: xgw
    * @Date: 2025/1/13
    */
    @GetMapping("/selectSessionBySearch")
    public AjaxResult selectSessionBySearch(@RequestParam("title") String title , @RequestParam("userId") Integer userId){
        return iSessionService.selectSessionBySearch(title,userId);
    }

    /**
    * @Description: 更新会话标题
    * @Param: 需要传递两人参数： session.id   session.title
    * @return:
    * @Author: xgw
    * @Date: 2025/1/13
    */
    @PutMapping("/updateSession")
    public AjaxResult updateSession(@RequestBody Session session){
        return AjaxResult.success("更新成功",iSessionService.updateSessionById(session.getId(),session.getTitle()));
    }


}
